var knex = require('../../util/knex')

const AdvertiServices = {
    add:async (req,res)=>{
        console.log('接收：',req)
        const image = req.image
        const link = req.link
        const data = await knex('adverti').insert({image,link}).then(result => {
            console.log('数据库：', result)
            return result
        }).catch(error => {
            console.log('error:',error);
        })
        return data
    },
    getList:async ()=>{
        const data = await knex('adverti').select().then(result => {
            // console.log('数据库：', result)
            return result
        }).catch(error => {
            console.log('error:',error);
        })
        return data
    },
    update:async (req)=>{
        console.log('接收：',req)
        const image = req.image
        const link = req.link

        const data = await knex('adverti').where({id:req.id}).update({image,link}).then(result => {
            console.log('数据库：', result)
            return result
        }).catch(error => {
            console.log('error:',error);
            return false
        })
        return data
    },
    delete:async (req)=>{
        console.log('接收：',req.id)
        const data = await knex('adverti').where({id:req.id}).del().then(result => {
            console.log('数据库：', result)
            return result
        }).catch(error => {
            console.log('error:',error);
            return false
        })
        return data
    }
}

module.exports = AdvertiServices